<?php include_once '../include/header.php' ?>
<?php include_once '../../controllers/eventcontroller.php' ?>
<div id="panelNav">
    <div id="logo-featured"><img width="60" height="60"  src="../../Images/coupon.png" alt=""/><span>Loại sự kiện</span></div>
    <ul>
        <li><a class="hover" href="#"><img src="../../Images/icon_delete.png" class="multi_del qTip"  title="Xóa chọn" border="0"/></a></li>
        <li><a class="hover" href="create.php"><img src="../../Images/icon_new.png" class="qTip" title="Thêm dữ liệu" border="0"/></a></li>
    </ul>
</div><!--end #menu_news-->
<div id="content">
    <div id="main-container">        
        <input type="hidden" name="multi_del" id="multi_del" value=""/>
        <table class="mytable" cellspacing="0" style="margin-left:5px;border-collapse: collapse;border:1px solid #CAE8EA;">
            <tr>                
                <th>Loại sự kiện</th>
                <th>Hình ảnh</th>                
                <th>Chức năng</th>
            </tr>
            <?php foreach($list_type as $row){ ?>
            <tr class="data<?php echo $row["id"] ?>">                
                <td><?php echo $row["loaisukien"] ?></td>
                <td><img src="../../data/event/<?php echo $row["image"] ?>" /></td>
                <td>
                    <img title='Sửa thông tin' id_edit="<?php echo $row["id"] ?>" style="cursor: pointer;" class="edit" src="../../Images/icon_edit.png"/>
                    <img title='Xóa thông tin' id_delete="<?php echo $row["id"] ?>" style="cursor: pointer;" class="delete" src="../../Images/icon_del.png"/>
                </td>
            </tr>
            <?php }?>
        </table>
        <div class="paging" style="text-align: center;margin-top:10px;height:25px;"><?php echo $page->firs_page ?><?php echo $page->previous_page ?><?php echo "$page->page_links"; ?><?php echo $page->next_page ?><?php echo $page->last_page ?></div>
    </div>
    <!--Edit-->
    <div id="dialog" title="Sửa vận chuyển">
        <?php include_once("edit.php") ?>
    </div>
    <script type="text/javascript">
        $('#dialog').dialog({
                autoOpen: false,
                width: 600,
                modal:true,
                buttons: {
                "Sửa": function() {
                        $("#create").submit();
                },
                "Cancel": function() {
                        $(this).dialog("close");
                }
        }
        });

         function checkvalidate(){
            if($("#hinhthucvanchuyen").val() != ""){$("#hinhthucvanchuyen").css("border","1px solid #cecece");}else{$("#hinhthucvanchuyen").css("border","1px solid #cc1e1e");return false;}
            return true;
        }
        $(function(){
            $(".edit").click(function(){
                var id = $(this).attr("id_edit");
                $('#dialog').dialog('open');
                $.get("../../controllers/eventcontroller.php?action=suaevent&id="+id,null,function(data){
                    $("#loaisukien").val(data.loaisukien);                    
                    $("#data_id").val(data.id);                    
                    $("#gethinhanh").val(data.image);                    
                },"json");
            })
             $(".status").click(function(){
                var stt = $(this).attr("stt");
                var id = $(this).attr("id_stt");
                $.ajax({
                    url:"../../controllers/couponcontroller.php?action=status",
                    type:"POST",
                    data:{stt:""+stt,id:""+id},
                    success:function(data){
                        if(data == true){
                            location.reload();
                        }
                    }
                });
            })
            $(".delete").click(function(){
                var id = $(this).attr("id_delete");
                if(confirm("Bạn có muốn xóa bản ghi này không?")){
                  $.ajax({
                        url:"../../controllers/eventcontroller.php?action=xoa",
                        type:"POST",
                        data:{id:""+id},
                        success:function(data){
                            if(data == true){
                                $(".data"+id).fadeTo("slow", 0);
                                $(".data"+id).css("background","#f00");
                                $(".data"+id).slideUp("slow");
                            }
                        }
                  });
                }
            })
            $("#check_all").click(function(){
                var checked_status = this.checked;
                $(".table_id").each(function(){
                    this.checked = checked_status;
                });
            });
            $(".multi_del").click(function(){
                if(confirm("Bạn có muốn xóa những bản ghi này không?")){
                    var list_data_id = "";
                    var a = new Array();
                    $.each($(".table_id:checked"), function(index, item) {
                        var id = $(item).attr("value");
                        a.push(id);
                        list_data_id = a.join(';');
                    });
                    $("#multi_del").val(list_data_id);
                    $.ajax({
                        type:"POST",
                        url:"../../controllers/couponcontroller.php",
                        data:{action:"multidel",id:""+$("#multi_del").val()},
                        success:function(data){
                            if(data == true){
                                $.each($(".table_id:checked"), function(index, item) {
                                    var userid = $(item).attr("value");
                                    $(".data"+userid).css("background-color","#f00");
                                    $(".data"+userid).fadeTo("slow",0).slideUp("slow");
                                });
                            }
                        }
                    });
                    return false;
                }

            })
        });
    </script>
</div>
<?php include_once '../include/footer.php' ?>